package com.mall.admin.service;

import com.mall.commons.utils.PageResult;
import com.mall.domain.SmsFlashPromotion;
import com.mall.interface1.api.SmsFlashPromotionApi;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class SmsFlashPromotionService {

    @DubboReference
    private SmsFlashPromotionApi smsFlashPromotionApi;

    //添加活动
    public void create(SmsFlashPromotion smsFlashPromotion) {
        smsFlashPromotionApi.create(smsFlashPromotion);
    }

    //删除活动
    public void delete(Long id) {
        smsFlashPromotionApi.delete(id);
    }

    //根据活动名称分页查询
    public PageResult list(String keyword, Integer pageNum, Integer pageSize) {
        //获取活动分页数据
        List<SmsFlashPromotion> sfList = smsFlashPromotionApi.list(keyword,pageNum,pageSize);
        //获取总活动数
        Integer count = smsFlashPromotionApi.count(keyword,pageNum,pageSize);

        return new PageResult(pageNum,pageSize,count,sfList);
    }

    //修改上下线状态
    public void updateStatus(Long id, Integer status) {
        //根据id获取活动
        SmsFlashPromotion smsFlashPromotion = smsFlashPromotionApi.findById(id);
        smsFlashPromotion.setStatus(status);
        //修改线上线下状态
        smsFlashPromotionApi.updateStatus(smsFlashPromotion);
    }

    //编辑活动
    public void update(Long id, SmsFlashPromotion smsFlashPromotion) {
        smsFlashPromotion.setId(id);
        smsFlashPromotionApi.update(smsFlashPromotion);
    }

    //获取活动详情
    public SmsFlashPromotion findById(Long id) {
        return smsFlashPromotionApi.findById(id);
    }
}
